// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import { DemoOrganPromiseClient as Client } from '@demo/proto/organ/demo_organ_grpc_web_pb'

import { ComQuery as ComClass } from '@demo/proto/common/ws_common_pb'
import { TreeReq as TreeClass } from '@demo/proto/organ/demo_organ_pb'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

const setDisabled = (tree) => {
  tree.forEach((item) => {
    item.disabled = item.status === 2
    if (CORE.isArray(item.children)) setDisabled(item.children)
  })
}

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 结构树 —————————————————————————————— //

  async getTree(param, TIP = '查询组织树') {
    const DTO = CORE.grpcDTO(TreeClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryTree', DTO)
    return resp.contentList
  },
  transTree(arr) {
    setDisabled(arr)
    return arr
  },
}
